package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Integral;
import cn.wolfcode.trip.base.service.IIntegralService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//积分资源控制器
@RestController
@RequestMapping("/money")
public class MoneyController {
    @Autowired
    private IIntegralService integralService;

    /**
     * 查用户的积分余额
     * 资源:/money
     * 动作:Get
     */
    @GetMapping("/{userId}")
    public Object getBalance(@PathVariable Long userId){
        return integralService.getIntegralByUserId(userId);
    }
    /**
     * 更新积分余额
     * 资源:/money
     * 动作:Post
     */
    @PostMapping
    public Object updateBalance(Integral entity){
       integralService.saveOrUpdate(entity);
       return new JSONResult();
    }
}
